home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / admin / pacctmon < prev    next >
Encoding:
Korn shell script  |  1997-08-26  |  4.6 KB  |  130 lines

  1. #!/bin/ksh
  2. # @(#) pacctmon.ksh 1.2 96/03/16
  3. # 1990     john h. dubois iii (john@armory.com)
  4. # 92/03/15 change acctcom line to use -o (write rn procs in pacct format)
  5. # 92/05/29 keep track of dialout processes
  6. # 92/06/28 keep acct files in /usr/adm/pa
  7. #          use ln -f and umask 033 to avoid need for rm and chmod
  8. # 92/07/25 pk is kermit dialout now
  9. # 93/05/19 Stop recording dialout use; ttylogger does that
  10. # 93/06/15 changed stty onlcr->sane; needed when script is run by setpgrp
  11. # 94/08/05 Set umask
  12. # 94/12/08 Allow /usr/adm/pa to not exist, to indicate that only daily log
  13. #          should be kept.
  14. # 94/12/16 Only restart process monitor screen if it was running,
  15. #          called with argument 'start' (for use at boot time).
  16. # 94/12/24 Use ksh to get -ef test operator
  17. # 95/04/24 Give acctcom -h flag (show hog factor), since kcore stuff isn't
  18. #          esp. meaningful.
  19. # 95/07/08 Added stop capability, expanded help.
  20. # 95/08/26 Added status printing capability.
  21. # 95/08/28 Added f option to acctcom to get fork/exec flags and exit status
  22. # 95/12/04 Discard StopMon output in one more place.
  23. # 96/03/03 For 'clean', always restart monitoring.  Relying on detecting the
  24. #          old process to determine if a new one should be started was not
  25. #          reliable.
  26. # 96/03/16 Pipe acctcom output through tr to get rid of control characters,
  27. #          since output is likely to be sent to console tty (annoyance/danger
  28. #          of switch screen, media copy, etc. escape sequences)
  29.  
  30. # It would be nice to filter the output of acctcom to replace control chars
  31. # with ? for safety.  However, when its output is not a tty acctcom buffers
  32. # enough data that it does not give a realtime display.
  33.  
  34. # Save interesting info from process accounting logs & 
  35. # restart accounting with zero-length logfile
  36.  
  37. # make saved process accounting files be 644
  38. umask 033
  39.  
  40. . /usr/local/admin/setpath
  41. acctuser=sysinfo
  42. accttty=/dev/tty10
  43. lngname=${0##*/}
  44. StopMon="/usr/local/bin/maim -u $acctuser tail"
  45. Usage="Usage: $lngname [-h|start|stop|clean]"
  46. acctdir=/usr/adm
  47. archdir=$acctdir/pa
  48. accountFile=$acctdir/pacct
  49.  
  50. function StartMon {
  51.     nice -15 su $acctuser -c "
  52.     stty sane
  53.     cd /usr/adm
  54.     exec tail -32cf $accountFile | acctcom -hf" > $accttty < $accttty &
  55. }
  56.  
  57. case "$1" in
  58. "")
  59.     /usr/local/bin/maim -n -u $acctuser tail > /dev/null 2>&1 &&
  60.     print "The process accounting monitor is running." ||
  61.     print "The process accounting monitor is not running."
  62.     exit 0
  63.     ;;
  64. start)
  65.     $StopMon > /dev/null 2>&1
  66.     StartMon
  67.     ;;
  68. stop)
  69.     $StopMon
  70.     ;;
  71. clean)    # daily cleanup
  72.     # Put any special record archiving here, as in this example.
  73.     # Send header to /dev/null
  74.     #acctcom -n '^cu$' -o /tmp/dialouts > /dev/null
  75.     #cat /tmp/dialouts >> dialouts
  76.  
  77.     umask 033    # make file readable if created
  78.  
  79.     if [ -d $archdir ]; then
  80.     todayacct=$archdir/`date +%d`
  81.     > $todayacct
  82.     # force new link
  83.     [ $todayacct -ef $accountFile ] || ln -f $todayacct $accountFile
  84.     else
  85.     mv $accountFile $accountFile-
  86.     > $accountFile
  87.     fi
  88.  
  89.     PATH=$PATH:/usr/lib/acct
  90.     accton
  91.     accton $accountFile
  92.     # Restart monitor so that it will read new pacct file
  93.     $StopMon > /dev/null 2>&1
  94.     StartMon
  95.     ;;
  96. -h)
  97.     print \
  98. "$lngname starts, stops, performs daily cleanup of, or reports the status of a
  99. process accounting monitor.  The monitor uses the process accounting system to
  100. display the name and other information about each process as it exits.  This is
  101. done by turning on process accounting and then reading from the end of the
  102. process accounting file as process accounting records are added to it.
  103. $Usage
  104. $lngname -h prints this help.
  105. $lngname without any arguments reports whether a monitor is currently running
  106.      or not.
  107. $lngname start  kills any currently running instance of $lngname (actually, it
  108.      kills any 'tail' process being run by the $lngname owner, $acctuser),
  109.      and then starts up a new instance of the monitor.
  110. $lngname stop   kills any currently running instance of $lngname.
  111. $lngname clean  cleans up the process acccounting files.  If the archiving
  112.      directory $archdir exists, a file named by the current day of the
  113.      month is created in it and the main process accounting file
  114.      ($accountFile) is linked to it.  If not, $accountFile is moved to
  115.      $accountFile-.  Then the process accounting system is stopped and
  116.      started so that it will begin logging to $accountFile again.
  117.      Finally, monitoring is stopped and started so that it too will use the
  118.      new file.
  119. See the acct(S), acct(FP), and acctcom(ADM) man pages for process accounting
  120. details."
  121.     exit 0
  122.     ;;
  123. *)
  124.     print -u2 \
  125. "$Usage
  126. Use -h for help"
  127.     exit 1
  128.     ;;
  129. esac
  130.